import 'dart:async';
import 'package:flutter/material.dart';
import 'package:test/locale/chinese_material_localizations.dart';
import 'package:test/locale/english_material_localizations.dart';

class GlobalMaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {

  const GlobalMaterialLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) => ['zh', 'en'].contains(locale.languageCode);

  @override
  Future<MaterialLocalizations> load(Locale locale) async {
    if (locale.languageCode == 'en') {
      return EnglishMaterialLocalizations();
    } else if (locale.languageCode == 'zh') {
      return ChineseMaterialLocalizations();
    }
    return EnglishMaterialLocalizations();
  }

  @override
  bool shouldReload(LocalizationsDelegate<MaterialLocalizations> old) {
    return false;
  }
}